package cn.tedu._06interceptor.base.config;

import cn.tedu._06interceptor.base.interceptors.MyInterceptor1;
import cn.tedu._06interceptor.base.interceptors.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
WebMvcConfigurer接口：Spring MVC的标准化配置接口
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       //1.添加拦截器【指定拦截策略】
        //1.策略一:拦截所有请求
      //  registry.addInterceptor(new MyInterceptor1());//注册拦截器
        //2.策略二:拦截指定单个请求（注册）
       // registry.addInterceptor(new MyInterceptor1())
        // .addPathPatterns("/v1/users/reg","/v1/users/login");
        //3.策略三:拦截指定的请求，比如拦截用户模块的所有请求
        //registry.addInterceptor(new MyInterceptor1())
        // .addPathPatterns("/v1/users/**");
        //4.排除指定的请求，比如拦截用户模块除了登录之外的所有请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/**")
//                .excludePathPatterns("/v1/users/login");
        //多个拦截器
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
    }
}
